home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / texts / mpindx50.lha / MPIndex50Src.lha / sh / RunMPIndex.c < prev   
C/C++ Source or Header  |  1996-05-14  |  31KB  |  1,423 lines

  1. // MPIndex - AmigaGuide Indexing program
  2. // Copyright (C) © 1996 Mark John Paddock
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mark@topic.demon.co.uk
  19. // mpaddock@cix.compulink.co.uk
  20.  
  21. extern long __stack = 16000;
  22.  
  23. extern long __oslibversion=39;
  24.  
  25. #define INTUI_V36_NAMES_ONLY
  26. #define INTUITION_IOBSOLETE_H
  27. #define ASL_V38_NAMES_ONLY
  28. #define __USE_SYSBASE 1
  29.  
  30. #include <proto/exec.h>
  31. #include <proto/dos.h>
  32. #include <proto/intuition.h>
  33. #include <proto/gadtools.h>
  34. #include <proto/graphics.h>
  35. #include <proto/utility.h>
  36. #include <proto/amigaguide.h>
  37. struct Library *AmigaGuideBase = NULL;
  38.  
  39. #include <intuition/gadgetclass.h>
  40.  
  41. #include <exec/memory.h>
  42.  
  43. #include <stdio.h>
  44. #include <string.h>
  45. #include <stdlib.h>
  46. #include <dos.h>
  47.  
  48. #include "MPIndex.h"
  49.  
  50. AMIGAGUIDECONTEXT     handle     = NULL;
  51. struct NewAmigaGuide    nag         = {NULL};
  52. struct AmigaGuideMsg *agm;            // message from amigaguide
  53.  
  54. //int sprintf(char *buffer,char *ctl, ...);
  55.  
  56. struct RDArgs *rdargs = NULL;
  57.  
  58. static const char Upper[129] =
  59. "                "
  60. "                "
  61. " !\"#$%&'()*+,-./"
  62. "0123456789:;<=>?"
  63. "@ABCDEFGHIJKLMNO"
  64. "PQRSTUVWXYZ[\\]^_"
  65. "`ABCDEFGHIJKLMNO"
  66. "PQRSTUVWXYZ{|}~ ";
  67.  
  68. #define toupper(x) (Upper[x])
  69.  
  70. const char Version[]="$VER: RunMPIndex 5.0 (10.5.96)";
  71.  
  72. struct MyNode *CurrNode = NULL;
  73.  
  74. struct FileName *FirstName = 0;
  75.  
  76. struct FileName **MyNamep=NULL;
  77.  
  78. struct MinList FileList;
  79.  
  80. int FileCnt=0;
  81.  
  82. struct MyNode {
  83.     struct MinNode Node;
  84.     struct FileName *FileName;
  85.     char *Name;
  86.     char *Title;
  87.     struct MyNode *MyNode;
  88.     struct MinList List;
  89.     char *UpperTitle;
  90. };
  91.  
  92. struct MyNode *FirstNode = 0;
  93.  
  94. struct MyWord {
  95.     struct Node Node;
  96.     struct MinList List;
  97.     struct MinList FileList;
  98.     struct MyNode **MyNode;
  99.     ULONG Count;
  100.     ULONG ActualCount;
  101.     char *UpperWord;
  102. };
  103.  
  104. struct NWNode {
  105.     struct MinNode Node;
  106.     struct MyWord *MyWord;
  107. };
  108.  
  109. struct SNode {
  110.     struct Node Node;
  111.     struct MyNode *MyNode;
  112. };
  113.  
  114. struct FNode {
  115.     struct MinNode Node;
  116.     struct FileName *FileName;
  117. };
  118.  
  119. struct MyWord AllWord;
  120.  
  121. struct MyWord **MyWordp;
  122. struct MyWord **MyWordps;
  123.  
  124. struct SNode *SNodes;
  125.  
  126. struct MinList Words;
  127. struct MinList EmptyList;
  128. struct MinList Nodes;
  129.  
  130. struct MyNode **MyNodep = NULL;
  131. struct MyNode **MyNodeps = NULL;
  132. struct MyWord *CurrWord = NULL;
  133.  
  134. ULONG WordCount = 0;
  135. ULONG NodeCount = 0;
  136.  
  137. char *command;
  138.  
  139. int ActualWordCount = 0;
  140.  
  141. BOOL All = TRUE;
  142. BOOL None = FALSE;
  143.  
  144. extern void *Chain = NULL;
  145. #define PUDDLE 64000
  146. #define THRESH 3000
  147.  
  148. #define TEMPLATE "FROM,COMMAND=COMM,PUBSCREEN/K"
  149. #define OPT_FROM    0
  150. #define OPT_COMM    1
  151. #define OPT_PUBS    2
  152.  
  153. #define OPT_COUNT    3
  154.  
  155. APTR
  156. Mystrdup(UBYTE *str);
  157.  
  158. APTR
  159. Mycalloc(ULONG size);
  160.  
  161. BOOL
  162. Mystrstr(char *a,char *b);
  163.  
  164. struct Requester RequestC;
  165.  
  166. void DisableWindow(void) {
  167.     InitRequester(&RequestC);
  168.     Request(&RequestC,MPIndexWnd);
  169.     // Wait pointer
  170.     SetWindowPointer(MPIndexWnd, WA_BusyPointer, TRUE,
  171.                           WA_PointerDelay, TRUE,
  172.                           TAG_END);
  173. }
  174.  
  175. void EnableWindow(void) {
  176.     EndRequest(&RequestC,MPIndexWnd);
  177.     SetWindowPointer(MPIndexWnd,
  178.                           TAG_END);
  179. }
  180.  
  181. void UnCurrent(void) {
  182.     int i;
  183.     GT_SetGadgetAttrs(MPIndexGadgets[GDX_Guide],MPIndexWnd,NULL,
  184.                             GTLV_Labels,~0,
  185.                             TAG_END);
  186.     for (i=0; i<FileCnt; ++i) {
  187.         MyNamep[i]->Current = FALSE;
  188.     }
  189.     GT_SetGadgetAttrs(MPIndexGadgets[GDX_Guide],MPIndexWnd,NULL,
  190.                             GTLV_Labels,&FileList,
  191.                             TAG_END);
  192. }
  193.  
  194. void NewCurrent(void) {
  195.     int i;
  196.     GT_SetGadgetAttrs(MPIndexGadgets[GDX_Guide],MPIndexWnd,NULL,
  197.                             GTLV_Labels,~0,
  198.                             TAG_END);
  199.     for (i=0; i<FileCnt; ++i) {
  200.         MyNamep[i]->Current = FALSE;
  201.     }
  202.     CurrNode->FileName->Current=TRUE;
  203.     GT_SetGadgetAttrs(MPIndexGadgets[GDX_Guide],MPIndexWnd,NULL,
  204.                             GTLV_Labels,&FileList,
  205.                             GTLV_MakeVisible, CurrNode->FileName->seq,
  206.                             TAG_END);
  207. }
  208.  
  209. BOOL CheckNode(struct MyNode *MyNode,char *c[],int max) {
  210.     struct NWNode *NWNode;
  211.     int i;
  212.     int cnt = 0;
  213.     BOOL chk[10]={0};
  214.     for (NWNode = (struct NWNode *)(MyNode->List.mlh_Head);
  215.           (cnt < max) && NWNode->Node.mln_Succ;
  216.           NWNode = (struct NWNode *)(NWNode->Node.mln_Succ)) {
  217.         for (i=0; i<max; ++i) {
  218.             if (!chk[i]) {
  219.                 if (Mystrstr(NWNode->MyWord->UpperWord,c[i])) {
  220.                     chk[i] = TRUE;
  221.                     ++cnt;
  222.                 }
  223.             }
  224.         }
  225.     }
  226.     if (cnt == max) {
  227.         return TRUE;
  228.     }
  229.     return FALSE;
  230. }
  231.  
  232. char nodebuffer[10];
  233.  
  234. void UpdateNodes(void) {
  235.     char *find;
  236.     char *findw;
  237.     struct MyNode **MyNodes;
  238.     struct SNode *SNode,*SNodes1;
  239.     char *p,*q;
  240.     char buffer[256];
  241.     char *c[10],*s[10];
  242.     int maxw,max,i;
  243.     BOOL multiw = FALSE;
  244.     BOOL found;
  245.  
  246.     for (i=0; i<FileCnt; ++i) {
  247.         MyNamep[i]->WordSel = FALSE;
  248.     }
  249.     GT_SetGadgetAttrs(MPIndexGadgets[GDX_Nodes],MPIndexWnd,NULL,
  250.                             GTLV_Labels,~0,
  251.                             TAG_END);
  252.     NewList((struct List *)&Nodes);
  253.     if (CurrWord) {
  254.         GT_GetGadgetAttrs(MPIndexGadgets[GDX_Find],MPIndexWnd,NULL,
  255.                                 GTST_String,&find,
  256.                                 TAG_END);
  257.         GT_GetGadgetAttrs(MPIndexGadgets[GDX_Search],MPIndexWnd,NULL,
  258.                                 GTST_String,&findw,
  259.                                 TAG_END);
  260.         if (Mystrstr(findw," ")) {
  261.             multiw = TRUE;
  262.             strcpy(buffer,findw);
  263.             p = buffer;
  264.             while (*p) {
  265.                 if (' ' == *p) {
  266.                     *p = 0;
  267.                 }
  268.                 else {
  269.                     *p = toupper(*p);
  270.                 }
  271.                 ++p;
  272.             }
  273.             ++p;
  274.             *p = 0;
  275.             maxw = strbpl(c,9,buffer);
  276.         }
  277.         MyNodes = MyNodeps;
  278.         SNodes1 = SNodes;
  279.         CurrWord->Count = 0;
  280.  
  281.         if (*find) {
  282.             if (Mystrstr(find," ")) {
  283.                 strcpy(buffer,find);
  284.                 p = buffer;
  285.                 while (*p) {
  286.                     if (' ' == *p) {
  287.                         *p = 0;
  288.                     }
  289.                     else {
  290.                         *p = toupper(*p);
  291.                     }
  292.                     ++p;
  293.                 }
  294.                 ++p;
  295.                 *p = 0;
  296.                 max = strbpl(s,9,buffer);
  297.                 for (SNode = (struct SNode *)(CurrWord->List.mlh_Head);
  298.                       SNode->Node.ln_Succ;
  299.                       SNode = (struct SNode *)(SNode->Node.ln_Succ)) {
  300.                     if (SNode->MyNode->FileName->Selected) {
  301.                         found = TRUE;
  302.                         for (i=0; found && (i<max); ++i) {
  303.                             if (!Mystrstr(SNode->MyNode->UpperTitle,s[i])) {
  304.                                 found = FALSE;
  305.                             }
  306.                         }
  307.                         if (found) {
  308.                             if (multiw) {
  309.                                 found = CheckNode(SNode->MyNode,c,maxw);
  310.                             }
  311.                             if (found) {
  312.                                 *SNodes1 = *SNode;
  313.                                 *MyNodes++ = SNode->MyNode;
  314.                                 AddTail((struct List *)&Nodes,&(SNodes1->Node));
  315.                                 ++SNodes1;
  316.                                 ++CurrWord->Count;
  317.                             }
  318.                         }
  319.                     }
  320.                 }
  321.             }
  322.             else {
  323.                 p = find;
  324.                 q = buffer;
  325.                 while (*p) {
  326.                     *q++ = toupper(*p++);
  327.                 }
  328.                 *q = 0;
  329.                 for (SNode = (struct SNode *)(CurrWord->List.mlh_Head);
  330.                       SNode->Node.ln_Succ;
  331.                       SNode = (struct SNode *)(SNode->Node.ln_Succ)) {
  332.                     if (SNode->MyNode->FileName->Selected) {
  333.                         if (Mystrstr(SNode->MyNode->UpperTitle,buffer)) {
  334.                             found = TRUE;
  335.                             if (multiw) {
  336.                                 found = CheckNode(SNode->MyNode,c,maxw);
  337.                             }
  338.                             if (found) {
  339.                                 *SNodes1 = *SNode;
  340.                                 *MyNodes++ = SNode->MyNode;
  341.                                 AddTail((struct List *)&Nodes,&(SNodes1->Node));
  342.                                 ++SNodes1;
  343.                                 ++CurrWord->Count;
  344.                             }
  345.                         }
  346.                     }
  347.                 }
  348.             }
  349.         }
  350.         else {
  351.             for (SNode = (struct SNode *)(CurrWord->List.mlh_Head);
  352.                   SNode->Node.ln_Succ;
  353.                   SNode = (struct SNode *)(SNode->Node.ln_Succ)) {
  354.                 if (SNode->MyNode->FileName->Selected) {
  355.                     found = TRUE;
  356.                     if (multiw) {
  357.                         found = CheckNode(SNode->MyNode,c,maxw);
  358.                     }
  359.                     if (found) {
  360.                         *SNodes1 = *SNode;
  361.                         *MyNodes++ = SNode->MyNode;
  362.                         AddTail((struct List *)&Nodes,&(SNodes1->Node));
  363.                         ++SNodes1;
  364.                         ++CurrWord->Count;
  365.                     }
  366.                 }
  367.             }
  368.         }
  369.     }
  370.     if (CurrWord && CurrWord->Count) {
  371.         for (i = 0; i<CurrWord->Count; ++i) {
  372.             MyNodeps[i]->FileName->WordSel = TRUE;
  373.         }
  374.         sprintf(nodebuffer,"%ld",CurrWord->Count);
  375.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_NodeCount],MPIndexWnd,NULL,
  376.                                 GTTX_Text,nodebuffer,
  377.                                 TAG_END);
  378.         CurrNode = MyNodeps[0];
  379.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Nodes],MPIndexWnd,NULL,
  380.                             GTLV_Labels,&Nodes,
  381.                             GTLV_Selected, 0,
  382.                             TAG_END);
  383.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Show],MPIndexWnd,NULL,
  384.                             GA_Disabled, FALSE,
  385.                             TAG_END);
  386.         NewCurrent();
  387.     }
  388.     else {
  389.         CurrNode = NULL;
  390.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_NodeCount],MPIndexWnd,NULL,
  391.                                 GTTX_Text,"0",
  392.                                 TAG_END);
  393.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Nodes],MPIndexWnd,NULL,
  394.                             GTLV_Labels,&Nodes,
  395.                             GTLV_Selected, ~0,
  396.                             TAG_END);
  397.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Show],MPIndexWnd,NULL,
  398.                             GA_Disabled, TRUE,
  399.                             TAG_END);
  400.         UnCurrent();
  401.     }
  402. }
  403.  
  404. char wordbuffer[10];
  405.  
  406. void UpdateWords(void) {
  407.     char *find;
  408.     int i,j,k;
  409.     struct FNode *FNode;
  410.     char pbuffer[256];
  411.     char *p;
  412.     char *c[10];
  413.     BOOL Found;
  414.     int maxw;
  415.  
  416.     if (None) {
  417.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_WordCount],MPIndexWnd,NULL,
  418.                                 GTTX_Text,"0",
  419.                                 TAG_END);
  420.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  421.                                 GTLV_Labels,~0,
  422.                                 TAG_END);
  423.         NewList((struct List *)&Words);
  424.         WordCount = 0;
  425.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  426.                                 GTLV_Labels,&Words,
  427.                                 GTLV_Selected, ~0,
  428.                                 TAG_END);
  429.         CurrWord = NULL;
  430.         UpdateNodes();
  431.         return;
  432.     }
  433.     GT_GetGadgetAttrs(MPIndexGadgets[GDX_Search],MPIndexWnd,NULL,
  434.                             GTST_String,&find,
  435.                             TAG_END);
  436.     if (*find && Mystrstr(find," ")) {
  437.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  438.                                 GTLV_Labels,~0,
  439.                                 TAG_END);
  440.         NewList((struct List *)&Words);
  441.         MyWordps[0] = MyWordp[0];
  442.         AddTail((struct List *)&Words,&(MyWordps[0]->Node));
  443.         CurrWord = MyWordp[0];
  444.         strcpy(pbuffer,find);
  445.         p = pbuffer;
  446.         while (*p) {
  447.             if (' ' == *p) {
  448.                 *p = 0;
  449.             }
  450.             else {
  451.                 *p = toupper(*p);
  452.             }
  453.             ++p;
  454.         }
  455.         ++p;
  456.         *p = 0;
  457.         maxw = strbpl(c,9,pbuffer);
  458.         for (i = 1, j = 1; i<ActualWordCount; ++i) {
  459.             Found = FALSE;
  460.             for (k=0; !Found && (k<maxw); ++k) {
  461.                 if (Mystrstr(MyWordp[i]->UpperWord,c[k])) {
  462.                     Found = TRUE;
  463.                 }
  464.             }
  465.             if (Found) {
  466.                 if (!All) {
  467.                     Found = FALSE;
  468.                     for (FNode = (struct FNode *)(MyWordp[i]->FileList.mlh_Head);
  469.                           !Found && FNode->Node.mln_Succ;
  470.                           FNode = (struct FNode *)(FNode->Node.mln_Succ)) {
  471.                         if (FNode->FileName->Selected) {
  472.                             Found = TRUE;
  473.                         }
  474.                     }
  475.                 }
  476.                 else {
  477.                     Found = TRUE;
  478.                 }
  479.                 if (Found) {
  480.                     MyWordps[j] = MyWordp[i];
  481.                     AddTail((struct List *)&Words,&(MyWordps[j]->Node));
  482.                     ++j;
  483.                 }
  484.             }
  485.         }
  486.         WordCount = j;
  487.         sprintf(wordbuffer,"%ld",j);
  488.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_WordCount],MPIndexWnd,NULL,
  489.                                 GTTX_Text,wordbuffer,
  490.                                 TAG_END);
  491.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  492.                                 GTLV_Labels,&Words,
  493.                                 GTLV_Selected, 0,
  494.                                 TAG_END);
  495.         UpdateNodes();
  496.     }
  497.     else if (ParsePatternNoCase(find,pbuffer,254)) {
  498.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  499.                                 GTLV_Labels,~0,
  500.                                 TAG_END);
  501.         NewList((struct List *)&Words);
  502.         for (i = 0, j = 0; i<ActualWordCount; ++i) {
  503.             if (!All) {
  504.                 Found = FALSE;
  505.                 for (FNode = (struct FNode *)(MyWordp[i]->FileList.mlh_Head);
  506.                       !Found && FNode->Node.mln_Succ;
  507.                       FNode = (struct FNode *)(FNode->Node.mln_Succ)) {
  508.                     if (FNode->FileName->Selected) {
  509.                         Found = TRUE;
  510.                     }
  511.                 }
  512.             }
  513.             else {
  514.                 Found = TRUE;
  515.             }
  516.             if (Found) {
  517.                 if (MatchPatternNoCase(pbuffer,MyWordp[i]->Node.ln_Name)) {
  518.                     MyWordps[j] = MyWordp[i];
  519.                     AddTail((struct List *)&Words,&(MyWordps[j]->Node));
  520.                     ++j;
  521.                 }
  522.             }
  523.         }
  524.         WordCount = j;
  525.         sprintf(wordbuffer,"%ld",WordCount);
  526.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_WordCount],MPIndexWnd,NULL,
  527.                                 GTTX_Text,wordbuffer,
  528.                                 TAG_END);
  529.         if (WordCount) {
  530.             CurrWord = MyWordps[0];
  531.         }
  532.         else {
  533.             CurrWord = NULL;
  534.         }
  535.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  536.                                 GTLV_Labels,&Words,
  537.                                 GTLV_Selected, WordCount?0:~0,
  538.                                 TAG_END);
  539.         UpdateNodes();
  540.     }
  541.     else {
  542.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  543.                                 GTLV_Labels,~0,
  544.                                 TAG_END);
  545.         NewList((struct List *)&Words);
  546.         for (i = 0, j = 0; i<ActualWordCount; ++i) {
  547.             if (!All) {
  548.                 Found = FALSE;
  549.                 for (FNode = (struct FNode *)(MyWordp[i]->FileList.mlh_Head);
  550.                       !Found && FNode->Node.mln_Succ;
  551.                       FNode = (struct FNode *)(FNode->Node.mln_Succ)) {
  552.                     if (FNode->FileName->Selected) {
  553.                         Found = TRUE;
  554.                     }
  555.                 }
  556.             }
  557.             else {
  558.                 Found = TRUE;
  559.             }
  560.             if (Found) {
  561.                 MyWordps[j] = MyWordp[i];
  562.                 AddTail((struct List *)&Words,&(MyWordps[j]->Node));
  563.                 ++j;
  564.             }
  565.         }
  566.         WordCount = j;
  567.         sprintf(wordbuffer,"%ld",WordCount);
  568.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_WordCount],MPIndexWnd,NULL,
  569.                                 GTTX_Text,wordbuffer,
  570.                                 TAG_END);
  571.         if (WordCount) {
  572.             CurrWord = MyWordp[0];
  573.         }
  574.         else {
  575.             CurrWord = NULL;
  576.         }
  577.         GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  578.                                 GTLV_Labels,&Words,
  579.                                 GTLV_Selected, WordCount?0:~0,
  580.                                 TAG_END);
  581.         if (WordCount) {
  582.             if (*find) {
  583.                 for (i = 0; (i<WordCount) && (toupper(*find) > toupper(*(MyWordps[i]->Node.ln_Name))); ++i) {
  584.                 }
  585.                 if (i < WordCount) {
  586.                     for (; (i<WordCount) && (stricmp(find,MyWordps[i]->Node.ln_Name)>0); ++i) {
  587.                     }
  588.                 }
  589.                 if (WordCount == i) {
  590.                     --i;
  591.                 }
  592.             }
  593.             else {
  594.                 i = 0;
  595.             }
  596.             CurrWord = MyWordps[i];
  597.             GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  598.                                     GTLV_Selected,     i,
  599.                                     GTLV_MakeVisible, i,
  600.                                     TAG_END);
  601.         }
  602.         UpdateNodes();
  603.     }
  604. }
  605.  
  606. static int ReqGad = 0;
  607. #define GAD_FIND        1
  608. #define GAD_SEARCH    2
  609.  
  610. int main(int argc,char **argv) {
  611.     long opts[OPT_COUNT] = {
  612.         (long)"Docs.Index",
  613.     };
  614.     int notdone = 1;
  615.     FILE *fp;
  616.     char *p,*t;
  617.     int seq;
  618.     char buffer[257];
  619.     struct MyWord *MyWord=NULL,**MyWordp1,**MyWordp2;
  620.     struct MyNode *MyNode,*LastNode = 0, **MyNodep1;
  621.     struct SNode *SNode;
  622.     struct FileName *FileName,*LastName=NULL,**MyNamep1;
  623.     struct MyNode **MyNodes;
  624.     struct FNode *FNode;
  625.     struct NWNode *NWNode;
  626.     int cnt = 0;
  627.     int cnt1;
  628.     int resx;
  629.     ULONG Signals;
  630.     char drive[FNSIZE],path[FMSIZE],node[FNSIZE],ext[FESIZE];
  631.     ULONG ASig = 0;
  632.  
  633.     if (argc) {
  634.         if (!(rdargs = ReadArgs((char *)TEMPLATE, opts, NULL))) {
  635.             PrintFault(IoErr(), NULL);
  636.             return 10;
  637.         }
  638.     }
  639.     if (!(AmigaGuideBase = OpenLibrary("amigaguide.library",34))) {
  640.         printf("Error opening amigaguide.library(34)\n");
  641.         return 10;
  642.     }
  643.     Chain = CreatePool(MEMF_CLEAR,PUDDLE,THRESH);
  644.     command = (char *)opts[OPT_COMM];
  645.     PubScreenName = (char *)opts[OPT_PUBS];
  646.     if (PubScreenName) {
  647.         if (!*PubScreenName) {
  648.             PubScreenName = NULL;
  649.         }
  650.     }
  651.     if (fp = fopen((char *)opts[OPT_FROM],"r")) {
  652.         NewList((struct List *)&Words);
  653.         NewList((struct List *)&EmptyList);
  654.         NewList((struct List *)&FileList);
  655.         p = fgets(buffer,256,fp);
  656.         while (p) {
  657.             while (p && (buffer[0] != '!')) {
  658.                 buffer[strlen(buffer)-1] = 0;
  659.                 if ('+' == buffer[0]) {
  660.                     FileName = Mycalloc(sizeof(struct FileName));
  661.                     if (!FirstName) {
  662.                         FirstName = FileName;
  663.                     }
  664.                     if (LastName) {
  665.                         LastName->FileName = FileName;
  666.                     }
  667.                     FileName->Name = Mystrdup(&(buffer[1]));
  668.                     strsfn(&buffer[1],drive,path,node,ext);
  669.                     FileName->Node.ln_Name = Mystrdup(node);
  670.                     FileName->Selected = TRUE;
  671.                     FileName->seq = FileCnt;
  672.                     AddTail((struct List *)&FileList,&(FileName->Node));
  673.                     LastName = FileName;
  674.                     ++FileCnt;
  675.                     p = fgets(buffer,256,fp);
  676.                 }
  677.                 else {
  678.                     if (!MyNamep) {
  679.                         MyNamep = Mycalloc((FileCnt+1)*sizeof(struct FileName *));
  680.                         MyNamep1 = MyNamep;
  681.                         LastName = FirstName;
  682.                         while (LastName) {
  683.                             *MyNamep1++ = LastName;
  684.                             LastName = LastName->FileName;
  685.                         }
  686.                     }
  687.                     MyNode = Mycalloc(sizeof(struct MyNode));
  688.                     NewList((struct List *)&(MyNode->List));
  689.                     if (!FirstNode) {
  690.                         FirstNode = MyNode;
  691.                     }
  692.                     if (LastNode) {
  693.                         LastNode->MyNode = MyNode;
  694.                     }
  695.                     seq = 0;
  696.                     t = buffer;
  697.                     while ('+' != *t) {
  698.                         seq *= 10;
  699.                         seq += (*t++ -'0');
  700.                     }
  701.                     ++t;
  702.                     MyNode->FileName = MyNamep[seq];
  703.                     MyNode->Name = Mystrdup(t);
  704.                     fgets(buffer,256,fp);
  705.                     buffer[strlen(buffer)-1] = 0;
  706.                     MyNode->Title = Mystrdup(buffer);
  707.                     t = MyNode->UpperTitle = Mycalloc(strlen(buffer)+1);
  708.                     p = buffer;
  709.                     while (*p) {
  710.                         *t++ = toupper(*p++);
  711.                     }
  712.                     *t = 0;
  713.                     LastNode = MyNode;
  714.                     ++cnt;
  715.                     p = fgets(buffer,256,fp);
  716.                 }
  717.             }
  718.             AllWord.Node.ln_Name = "#?";
  719.             AddTail((struct List *)&Words,&(AllWord.Node));
  720.             NewList((struct List *)&(AllWord.List));
  721.             NewList((struct List *)&(AllWord.FileList));
  722.             MyNodes = AllWord.MyNode = Mycalloc((cnt+1)*sizeof(struct MyNode *));
  723.             MyNodep = Mycalloc((cnt+1)*sizeof(struct MyNode *));
  724.             MyNodeps = Mycalloc((cnt+1)*sizeof(struct MyNode *));
  725.             SNodes = Mycalloc((cnt+1)*sizeof(struct SNode));
  726.             NodeCount = cnt;
  727.             MyNodep1 = MyNodep;
  728.             LastNode = FirstNode;
  729.             while (LastNode) {
  730.                 *MyNodep1++ = LastNode;
  731.                 SNode = Mycalloc(sizeof(struct SNode));
  732.                 SNode->MyNode = LastNode;
  733.                 SNode->Node.ln_Name = SNode->MyNode->Title;
  734.                 AddTail((struct List *)&(AllWord.List),&(SNode->Node));
  735.                 *MyNodes++ = SNode->MyNode;
  736.                 LastNode = LastNode->MyNode;
  737.             }
  738.             LastName = FirstName;
  739.             while (LastName) {
  740.                 FNode = Mycalloc(sizeof(struct FNode));
  741.                 FNode->FileName = LastName;
  742.                 AddTail((struct List *)&(AllWord.FileList),(struct Node *)&(FNode->Node));
  743.                 LastName = LastName->FileName;
  744.             }
  745.             cnt = 0;
  746.             cnt1 = 0;
  747.             while (p) {
  748.                 if ('!' == buffer[0]) {
  749.                     if (cnt1) {
  750.                         BOOL found;
  751.                         MyNodes = MyWord->MyNode = Mycalloc((cnt1+1)*sizeof(struct MyNode *));
  752.                         for (SNode = (struct SNode *)(MyWord->List.mlh_Head);
  753.                               SNode->Node.ln_Succ;
  754.                               SNode = (struct SNode *)(SNode->Node.ln_Succ)) {
  755.                             *MyNodes++ = SNode->MyNode;
  756.                             found = FALSE;
  757.                             for (FNode = (struct FNode *)(MyWord->FileList.mlh_Head);
  758.                                   !found && FNode->Node.mln_Succ;
  759.                                   FNode = (struct FNode *)(FNode->Node.mln_Succ)) {
  760.                                 if (SNode->MyNode->FileName == FNode->FileName) {
  761.                                     found = TRUE;
  762.                                 }
  763.                             }
  764.                             if (!found) {
  765.                                 FNode = Mycalloc(sizeof(struct FNode));
  766.                                 FNode->FileName = SNode->MyNode->FileName;
  767.                                 AddTail((struct List *)&(MyWord->FileList),(struct Node *)&(FNode->Node));
  768.                             }
  769.                         }
  770.                         MyWord->ActualCount = cnt1;
  771.                         MyWord->Count = cnt1;
  772.                     }
  773.                     cnt1 = 0;
  774.                     buffer[strlen(buffer)-1] = 0;
  775.                     MyWord = Mycalloc(sizeof(struct MyWord));
  776.                     MyWord->Node.ln_Name = Mystrdup(&(buffer[1]));
  777.                     t = MyWord->UpperWord = Mycalloc(strlen(&(buffer[1]))+1);
  778.                     p = &(buffer[1]);
  779.                     while (*p) {
  780.                         *t++ = toupper(*p++);
  781.                     }
  782.                     *t = 0;
  783.                     AddTail((struct List *)&Words,&(MyWord->Node));
  784.                     NewList((struct List *)&(MyWord->List));
  785.                     NewList((struct List *)&(MyWord->FileList));
  786.                     cnt++;
  787.                 }
  788.                 else {
  789.                     SNode = Mycalloc(sizeof(struct SNode));
  790.                     SNode->MyNode = MyNodep[atoi(p)];
  791.                     SNode->Node.ln_Name = SNode->MyNode->Title;
  792.                     AddTail((struct List *)&(MyWord->List),&(SNode->Node));
  793.                     NWNode = Mycalloc(sizeof(struct NWNode));
  794.                     NWNode->MyWord = MyWord;
  795.                     AddTail((struct List *)&(SNode->MyNode->List),(struct Node *)&(NWNode->Node));
  796.                     cnt1++;
  797.                 }
  798.                 p = fgets(buffer,256,fp);
  799.             }
  800.         }
  801.         if (cnt1) {
  802.             BOOL found;
  803.             MyNodes = MyWord->MyNode = Mycalloc((cnt1+1)*sizeof(struct MyNode *));
  804.             for (SNode = (struct SNode *)(MyWord->List.mlh_Head);
  805.                   SNode->Node.ln_Succ;
  806.                   SNode = (struct SNode *)(SNode->Node.ln_Succ)) {
  807.                 *MyNodes++ = SNode->MyNode;
  808.                 found = FALSE;
  809.                 for (FNode = (struct FNode *)(MyWord->FileList.mlh_Head);
  810.                       !found && FNode->Node.mln_Succ;
  811.                       FNode = (struct FNode *)(FNode->Node.mln_Succ)) {
  812.                     if (SNode->MyNode->FileName == FNode->FileName) {
  813.                         found = TRUE;
  814.                     }
  815.                 }
  816.                 if (!found) {
  817.                     FNode = Mycalloc(sizeof(struct FNode));
  818.                     FNode->FileName = SNode->MyNode->FileName;
  819.                     AddTail((struct List *)&(MyWord->FileList),(struct Node *)&(FNode->Node));
  820.                 }
  821.             }
  822.             MyWord->ActualCount = cnt1;
  823.             MyWord->Count = cnt1;
  824.         }
  825.         WordCount = cnt+1;
  826.         MyWordp = Mycalloc((cnt+2)*sizeof(struct MyWord *));
  827.         MyWordps = Mycalloc((cnt+2)*sizeof(struct MyWord *));
  828.         MyWordp1 = MyWordp;
  829.         MyWordp2 = MyWordps;
  830.         for (MyWord = (struct MyWord *)(Words.mlh_Head);
  831.                 MyWord->Node.ln_Succ;
  832.                 MyWord = (struct MyWord *)(MyWord->Node.ln_Succ)) {
  833.             *MyWordp1++ = MyWord;
  834.             *MyWordp2++ = MyWord;
  835.         }
  836.         ActualWordCount = WordCount;
  837.         if (!SetupScreen()) {
  838.             if (!OpenMPIndexWindow()) {
  839.                 UpdateWords();
  840.                 nag.nag_BaseName        = "RunMPIndex";
  841.                 nag.nag_Name            = "RunMPIndex.guide";
  842.                 nag.nag_ClientPort    = "RunMPIndex_HELP";
  843.                 nag.nag_Flags            = HTF_NOACTIVATE;
  844.                 nag.nag_PubScreen     = NULL;
  845.                 handle = OpenAmigaGuideAsync(&nag, TAG_END);
  846.                 if (handle) {
  847.                    ASig = AmigaGuideSignal(handle);
  848.                     while (agm = GetAmigaGuideMsg(handle)) {
  849.                         ReplyAmigaGuideMsg(agm);
  850.                     }
  851.                 }
  852.                 while (notdone) {
  853.                     Signals = Wait(ASig | (1L<<MPIndexWnd->UserPort->mp_SigBit) | HookData.Signal | (1L<<SigNode));
  854.                     if (Signals & ASig) {
  855.                         while (agm = GetAmigaGuideMsg(handle)) {
  856.                             ReplyAmigaGuideMsg(agm);
  857.                         }
  858.                     }
  859.                     if (Signals & (1L<<MPIndexWnd->UserPort->mp_SigBit)) {
  860.                         notdone = HandleMPIndexIDCMP();
  861.                     }
  862.                     if (Signals & (1L<<SigNode)) {
  863.                         DisableWindow();
  864.                         UpdateNodes();
  865.                         EnableWindow();
  866.                         ReqGad = GAD_FIND;
  867.                     }
  868.                     if (Signals & HookData.Signal) {
  869.                         DisableWindow();
  870.                         UpdateWords();
  871.                         EnableWindow();
  872.                         ReqGad = GAD_SEARCH;
  873.                     }
  874.                 }
  875.                 if (handle) {
  876.                     while (agm = GetAmigaGuideMsg(handle)) {
  877.                         ReplyAmigaGuideMsg(agm);
  878.                     }
  879.                     CloseAmigaGuide(handle);
  880.                 }
  881.                 resx = 0;
  882.             }
  883.             else {
  884.                 printf("Error opening window\n");
  885.                 resx = 10;
  886.             }
  887.             CloseMPIndexWindow();
  888.         }
  889.         else {
  890.             printf("Error settings up screen\n");
  891.             resx = 10;
  892.         }
  893.         CloseDownScreen();
  894.         fclose(fp);
  895.     }
  896.     else {
  897.         printf("Error opening %s\n",(char *)opts[OPT_FROM]);
  898.         resx = 10;
  899.     }
  900.     if (rdargs) {
  901.         FreeArgs(rdargs);
  902.     }
  903.     if (Chain) {
  904.         DeletePool(Chain);
  905.     }
  906.     CloseLibrary(AmigaGuideBase);
  907.     return resx;
  908. }
  909.  
  910. extern void
  911. ReqClear(void) {
  912.     int i;
  913.     BOOL act = FALSE;
  914.     if (GAD_FIND == ReqGad) {
  915.         for (i=0; !act && (i<10); ++i) {
  916.             act = ActivateGadget(MPIndexGadgets[GDX_Find],MPIndexWnd,NULL);
  917.             if (!act) {
  918.                 Delay(i+1);
  919.             }
  920.         }
  921.         ReqGad = 0;
  922.         return;
  923.     }
  924.     if (GAD_SEARCH == ReqGad) {
  925.         for (i=0; !act && (i<10); ++i) {
  926.             act = ActivateGadget(MPIndexGadgets[GDX_Search],MPIndexWnd,NULL);
  927.             if (!act) {
  928.                 Delay(i+1);
  929.             }
  930.         }
  931.         ReqGad = 0;
  932.         return;
  933.     }
  934. }
  935.  
  936. void
  937. UpdateGuide(ULONG act) {
  938.     int i;
  939.     GT_SetGadgetAttrs(MPIndexGadgets[GDX_Guide],MPIndexWnd,NULL,
  940.                             GTLV_Labels,~0,
  941.                             TAG_END);
  942.     if (0 == act) {
  943.         All = TRUE;
  944.         None = FALSE;
  945.         for (i=0; i<FileCnt; ++i) {
  946.             MyNamep[i]->Selected = TRUE;
  947.         }
  948.     }
  949.     else {
  950.         if (1 == act) {
  951.             All = FALSE;
  952.             None = TRUE;
  953.             for (i=0; i<FileCnt; ++i) {
  954.                 MyNamep[i]->Selected = FALSE;
  955.             }
  956.         }
  957.     }
  958.     UpdateWords();
  959.     GT_SetGadgetAttrs(MPIndexGadgets[GDX_Guide],MPIndexWnd,NULL,
  960.                             GTLV_Labels,&FileList,
  961.                             TAG_END);
  962. }
  963.  
  964. int SearchClicked( void )
  965. {
  966.     /* routine when gadget "" is clicked. */
  967.     if (MPIndexMsg.Code == 0x5f) {
  968.         if (handle) {
  969.             while (agm = GetAmigaGuideMsg(handle)) {
  970.                 ReplyAmigaGuideMsg(agm);
  971.             }
  972.             SendAmigaGuideCmdA(handle,"LINK g-search",NULL);
  973.             while (agm = GetAmigaGuideMsg(handle)) {
  974.                 ReplyAmigaGuideMsg(agm);
  975.             }
  976.         }
  977.         ActivateGadget((struct Gadget *)MPIndexMsg.IAddress,MPIndexWnd,NULL);
  978.     }
  979.     return 1;
  980. }
  981.  
  982. int WordsClicked( void )
  983. {
  984.     /* routine when gadget "" is clicked. */
  985.     CurrWord = MyWordps[MPIndexMsg.Code];
  986.     DisableWindow();
  987.     UpdateNodes();
  988.     EnableWindow();
  989.     return 1;
  990. }
  991.  
  992. int NodesClicked( void )
  993. {
  994.     static ULONG secs = 0;
  995.     static ULONG micros = 0;
  996.     static struct MyNode *LastClickedNode = NULL;
  997.     /* routine when gadget "" is clicked. */
  998.     GT_SetGadgetAttrs(MPIndexGadgets[GDX_Show],MPIndexWnd,NULL,
  999.                             GA_Disabled, FALSE,
  1000.                             TAG_END);
  1001.     CurrNode = MyNodeps[MPIndexMsg.Code];
  1002.     if (CurrNode == LastClickedNode) {
  1003.         if (DoubleClick(secs,micros,MPIndexMsg.Seconds,MPIndexMsg.Micros)) {
  1004.             ShowClicked();
  1005.         }
  1006.     }
  1007.     LastClickedNode = CurrNode;
  1008.     NewCurrent();
  1009.     secs = MPIndexMsg.Seconds;
  1010.     micros = MPIndexMsg.Micros;
  1011.     return 1;
  1012. }
  1013.  
  1014. int MPIndexCloseWindow( void )
  1015. {
  1016.     /* routine for "IDCMP_CLOSEWINDOW". */
  1017.     CurrNode = NULL;
  1018.     UnCurrent();
  1019.     return 0;
  1020. }
  1021.  
  1022. int MPIndexVanillaKey( void )
  1023. {
  1024.     /* routine for "IDCMP_VANILLAKEY". */
  1025.     int res;
  1026.     ULONG pos = 0;
  1027.     switch (MPIndexMsg.Code) {
  1028.     case 'h':
  1029.     case 'H':
  1030.         ShowClicked();
  1031.         res = 1;
  1032.         break;
  1033.     case 'c':
  1034.     case 'C':
  1035.         res = 0;
  1036.         break;
  1037.     case 0x1b:
  1038.         res = 0;
  1039.         break;
  1040.     case 's':
  1041.     case 'S':
  1042.         ActivateGadget(MPIndexGadgets[GDX_Search],MPIndexWnd,NULL);
  1043.         res = 1;
  1044.         break;
  1045.     case 'u':
  1046.     case 'U':
  1047.         ActivateGadget(MPIndexGadgets[GDX_Find],MPIndexWnd,NULL);
  1048.         res = 1;
  1049.         break;
  1050.     case 'w':
  1051.         if (WordCount) {
  1052.             DisableWindow();
  1053.             GT_GetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  1054.                                     GTLV_Selected, &pos,
  1055.                                     TAG_END);
  1056.             if ((ULONG)~0 == pos) {
  1057.                 pos = 0;
  1058.             }
  1059.             else {
  1060.                 ++pos;
  1061.                 if (pos == WordCount) {
  1062.                     pos = 0;
  1063.                 }
  1064.             }
  1065.             GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  1066.                                     GTLV_Selected, pos,
  1067.                                     GTLV_MakeVisible, pos,
  1068.                                     TAG_END);
  1069.             CurrWord = MyWordps[pos];
  1070.             UpdateNodes();
  1071.             EnableWindow();
  1072.         }
  1073.         res = 1;
  1074.         break;
  1075.     case 'W':
  1076.         if (WordCount) {
  1077.             DisableWindow();
  1078.             GT_GetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  1079.                                     GTLV_Selected, &pos,
  1080.                                     TAG_END);
  1081.             if ((ULONG)~0 == pos) {
  1082.                 pos = WordCount-1;
  1083.             }
  1084.             else {
  1085.                 if (0 == pos) {
  1086.                     pos = WordCount-1;
  1087.                 }
  1088.                 else {
  1089.                     --pos;
  1090.                 }
  1091.             }
  1092.             GT_SetGadgetAttrs(MPIndexGadgets[GDX_Words],MPIndexWnd,NULL,
  1093.                                     GTLV_Selected, pos,
  1094.                                     GTLV_MakeVisible, pos,
  1095.                                     TAG_END);
  1096.             CurrWord = MyWordps[pos];
  1097.             UpdateNodes();
  1098.             EnableWindow();
  1099.         }
  1100.         res = 1;
  1101.         break;
  1102.     case 'n':
  1103.         if (CurrWord && CurrWord->Count) {
  1104.             DisableWindow();
  1105.             GT_GetGadgetAttrs(MPIndexGadgets[GDX_Nodes],MPIndexWnd,NULL,
  1106.                                     GTLV_Selected, &pos,
  1107.                                     TAG_END);
  1108.             if ((ULONG)~0 == pos) {
  1109.                 pos = 0;
  1110.             }
  1111.             else {
  1112.                 ++pos;
  1113.                 if (pos == CurrWord->Count) {
  1114.                     pos = 0;
  1115.                 }
  1116.             }
  1117.             GT_SetGadgetAttrs(MPIndexGadgets[GDX_Nodes],MPIndexWnd,NULL,
  1118.                                     GTLV_Selected, pos,
  1119.                                     GTLV_MakeVisible, pos,
  1120.                                     TAG_END);
  1121.             GT_SetGadgetAttrs(MPIndexGadgets[GDX_Show],MPIndexWnd,NULL,
  1122.                                     GA_Disabled, FALSE,
  1123.                                     TAG_END);
  1124.             CurrNode = MyNodeps[pos];
  1125.             NewCurrent();
  1126.             EnableWindow();
  1127.         }
  1128.         res = 1;
  1129.         break;
  1130.     case 'N':
  1131.         if (CurrWord && CurrWord->Count) {
  1132.             DisableWindow();
  1133.             GT_GetGadgetAttrs(MPIndexGadgets[GDX_Nodes],MPIndexWnd,NULL,
  1134.                                     GTLV_Selected, &pos,
  1135.                                     TAG_END);
  1136.             if ((ULONG)~0 == pos) {
  1137.                 pos = CurrWord->Count-1;
  1138.             }
  1139.             else {
  1140.                 if (0 == pos) {
  1141.                     pos = CurrWord->Count-1;
  1142.                 }
  1143.                 else {
  1144.                     --pos;
  1145.                 }
  1146.             }
  1147.             GT_SetGadgetAttrs(MPIndexGadgets[GDX_Nodes],MPIndexWnd,NULL,
  1148.                                     GTLV_Selected, pos,
  1149.                                     GTLV_MakeVisible, pos,
  1150.                                     TAG_END);
  1151.             GT_SetGadgetAttrs(MPIndexGadgets[GDX_Show],MPIndexWnd,NULL,
  1152.                                     GA_Disabled, FALSE,
  1153.                                     TAG_END);
  1154.             CurrNode = MyNodeps[pos];
  1155.             NewCurrent();
  1156.             EnableWindow();
  1157.         }
  1158.         res = 1;
  1159.         break;
  1160.     case 'a':
  1161.     case 'A':
  1162.         DisableWindow();
  1163.         UpdateGuide(0);
  1164.         EnableWindow();
  1165.         res = 1;
  1166.         break;
  1167.     case 'o':
  1168.     case 'O':
  1169.         DisableWindow();
  1170.         UpdateGuide(1);
  1171.         EnableWindow();
  1172.         res = 1;
  1173.         break;
  1174.     default:
  1175.         res = 1;
  1176.         break;
  1177.     }
  1178.     return res;
  1179. }
  1180.  
  1181. int MPIndexRawKey( void )
  1182. {
  1183.     /* routine for "IDCMP_RAWKEY". */
  1184.     int res;
  1185.     char buffer[256];
  1186.     switch (MPIndexMsg.Code) {
  1187.     case 0x5f:
  1188.         if (handle) {
  1189.             while (agm = GetAmigaGuideMsg(handle)) {
  1190.                 ReplyAmigaGuideMsg(agm);
  1191.             }
  1192.             sprintf(buffer,"LINK %s",GuideNode);
  1193.             SendAmigaGuideCmdA(handle,buffer,NULL);
  1194.             while (agm = GetAmigaGuideMsg(handle)) {
  1195.                 ReplyAmigaGuideMsg(agm);
  1196.             }
  1197.         }
  1198.         res = 1;
  1199.         break;
  1200.     default:
  1201.         res = 1;
  1202.         break;
  1203.     }
  1204.     return res;
  1205. }
  1206.  
  1207. int ShowClicked( void )
  1208. {
  1209.     char buffer[256];
  1210.     char buffer1[128];
  1211.     /* routine when gadget "S_how" is clicked. */
  1212.     if (CurrNode) {
  1213.         DisableWindow();
  1214.         sprintf(buffer1,"%s/%s",CurrNode->FileName->Name,CurrNode->Name);
  1215.         if (command) {
  1216.             sprintf(buffer,command,buffer1);
  1217.             system(buffer);
  1218.         }
  1219.         else {
  1220.             if (handle) {
  1221.                 while (agm = GetAmigaGuideMsg(handle)) {
  1222.                     ReplyAmigaGuideMsg(agm);
  1223.                 }
  1224.                 sprintf(buffer,"LINK %s",buffer1);
  1225.                 SendAmigaGuideCmdA(handle,buffer,NULL);
  1226.                 while (agm = GetAmigaGuideMsg(handle)) {
  1227.                     ReplyAmigaGuideMsg(agm);
  1228.                 }
  1229.             }
  1230.         }
  1231.         EnableWindow();
  1232.     }
  1233.     return 1;
  1234. }
  1235.  
  1236. int CancelClicked( void )
  1237. {
  1238.     /* routine when gadget "_Cancel" is clicked. */
  1239.     CurrNode = NULL;
  1240.     UnCurrent();
  1241.     return 0;
  1242. }
  1243.  
  1244. int FindClicked( void )
  1245. {
  1246.     if (MPIndexMsg.Code == 0x5f) {
  1247.         if (handle) {
  1248.             while (agm = GetAmigaGuideMsg(handle)) {
  1249.                 ReplyAmigaGuideMsg(agm);
  1250.             }
  1251.             SendAmigaGuideCmdA(handle,"LINK g-subset",NULL);
  1252.             while (agm = GetAmigaGuideMsg(handle)) {
  1253.                 ReplyAmigaGuideMsg(agm);
  1254.             }
  1255.         }
  1256.         ActivateGadget((struct Gadget *)MPIndexMsg.IAddress,MPIndexWnd,NULL);
  1257.     }
  1258.     return 1;
  1259. }
  1260.  
  1261. int GuideClicked(void) {
  1262.     int i;
  1263.     DisableWindow();
  1264.     if (MyNamep[MPIndexMsg.Code]->Selected) {
  1265.         MyNamep[MPIndexMsg.Code]->Selected = FALSE;
  1266.     }
  1267.     else {
  1268.         MyNamep[MPIndexMsg.Code]->Selected = TRUE;
  1269.     }
  1270.     None = TRUE;
  1271.     All = TRUE;
  1272.     for (i=0; i<FileCnt; ++i) {
  1273.         if (MyNamep[i]->Selected) {
  1274.             None = FALSE;
  1275.         }
  1276.         else {
  1277.             All = FALSE;
  1278.         }
  1279.     }
  1280.     UpdateGuide(2);
  1281.     EnableWindow();
  1282.     return 1;
  1283. }
  1284.  
  1285. int AllClicked(void) {
  1286.     UpdateGuide(0);
  1287.     return 1;
  1288. }
  1289.  
  1290. int NoneClicked(void) {
  1291.     UpdateGuide(1);
  1292.     return 1;
  1293. }
  1294.  
  1295. APTR
  1296. Mystrdup(UBYTE *str) {
  1297.     return strcpy(Mycalloc(strlen(str)+1),str);
  1298. }
  1299.  
  1300. APTR
  1301. Mycalloc(ULONG size) {
  1302.     APTR res;
  1303.     if (Chain) {
  1304.         res = AllocPooled(Chain,size);
  1305.     }
  1306.     else {
  1307.         res = calloc(1,size);
  1308.     }
  1309.     if (res) {
  1310.         return res;
  1311.     }
  1312.     if (rdargs) {
  1313.         FreeArgs(rdargs);
  1314.     }
  1315.     if (Chain) {
  1316.         DeletePool(Chain);
  1317.     }
  1318.     printf("Out of memory\n");
  1319.     exit(10);
  1320. }
  1321.  
  1322. // Note both strings are in upper case
  1323. BOOL
  1324. Mystrstr(char *a,char *b) {
  1325.     char *p;
  1326.     int al,bl,t;
  1327.     if (!*b) {
  1328.         return TRUE;
  1329.     }
  1330.     if (!*a) {
  1331.         return FALSE;
  1332.     }
  1333.     if (!b[1]) {
  1334.         for (p=a; *p; ++p) {
  1335.             if (*p == *b) {
  1336.                 return TRUE;
  1337.             }
  1338.         }
  1339.         return FALSE;
  1340.     }
  1341.     if (!a[1]) {
  1342.         return FALSE;
  1343.     }
  1344.     if (!b[2]) {
  1345.         for (p=a; p[1]; ++p) {
  1346.             if ((*p == *b) && (p[1] == b[1])) {
  1347.                 return TRUE;
  1348.             }
  1349.         }
  1350.         return FALSE;
  1351.     }
  1352.     if (!a[2]) {
  1353.         return FALSE;
  1354.     }
  1355.     al = strlen(a);
  1356.     bl = strlen(b);
  1357.     if (al < bl) {
  1358.         return FALSE;
  1359.     }
  1360.     if (al == bl) {
  1361.         if (*a == *b) {
  1362.             if (a[1] == b[1]) {
  1363.                 if (!strcmp(&a[2],&b[2])) {
  1364.                     return TRUE;
  1365.                 }
  1366.             }
  1367.         }
  1368.         return FALSE;
  1369.     }
  1370.     t = bl-2;
  1371.     if (al == (bl+1)) {
  1372.         if (*a == *b) {
  1373.             if (a[1] == b[1]) {
  1374.                 if (!strncmp(&a[2],&b[2],t)) {
  1375.                     return TRUE;
  1376.                 }
  1377.             }
  1378.         }
  1379.         if (a[1] == *b) {
  1380.             if (a[2] == b[1]) {
  1381.                 if (!strcmp(&a[3],&b[2])) {
  1382.                     return TRUE;
  1383.                 }
  1384.             }
  1385.         }
  1386.         return FALSE;
  1387.     }
  1388.     if (al == (bl+2)) {
  1389.         if (*a == *b) {
  1390.             if (a[1] == b[1]) {
  1391.                 if (!strncmp(&a[2],&b[2],t)) {
  1392.                     return TRUE;
  1393.                 }
  1394.             }
  1395.         }
  1396.         if (a[1] == *b) {
  1397.             if (a[2] == b[1]) {
  1398.                 if (!strncmp(&a[3],&b[2],t)) {
  1399.                     return TRUE;
  1400.                 }
  1401.             }
  1402.         }
  1403.         if (a[2] == *b) {
  1404.             if (a[3] == b[1]) {
  1405.                 if (!strcmp(&a[4],&b[2])) {
  1406.                     return TRUE;
  1407.                 }
  1408.             }
  1409.         }
  1410.         return FALSE;
  1411.     }
  1412.     for (p = a; p[2]; ++p) {
  1413.         if (*b == *p) {
  1414.             if (b[1] == p[1]) {
  1415.                 if (!strncmp(&p[2],&b[2],t)) {
  1416.                     return TRUE;
  1417.                 }
  1418.             }
  1419.         }
  1420.     }
  1421.     return FALSE;
  1422. }
  1423.